package xin.mashibo.wanjiobutest.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import xin.mashibo.wanjiobutest.R;
import xin.mashibo.wanjiobutest.vo.CardConsumeExtend;

import static xin.mashibo.wanjiobutest.constant.ServiceConstant.CARDOWNER_KEY;
import static xin.mashibo.wanjiobutest.constant.ServiceConstant.CONSUME_LIST_KEY;

/**
 * @author MaShibo
 *         on 2018/3/22
 */
public class CardConsumeActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);
        setTitle(getString(R.string.cardConsumeActivityTitle));
        ListView listView = findViewById(R.id.list_view);
        List<CardConsumeExtend> extendList = getIntent().getBundleExtra(CONSUME_LIST_KEY).getParcelableArrayList(CONSUME_LIST_KEY);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, generateDataList(extendList));
        listView.setAdapter(adapter);
    }


    /**
     * 根据卡片消费记录生成数据列表
     *
     * @param extendList 卡片消费记录
     * @return 数据列表
     */
    private List<String> generateDataList(List<CardConsumeExtend> extendList) {
        List<String> dataList = new ArrayList<>(extendList.size());
        for (CardConsumeExtend extend : extendList) {
            String consume =
                    "applicationId：" + extend.getApplicationId() + "\n" +
                            "recordLength：" + extend.getRecordLength() + "\n" +
                            "applicationLockFlag：" + extend.getApplicationLockFlag() + "\n" +
                            "tollRoadNetworkId：" + extend.getTollRoadNetworkId() + "\n" +
                            "tollStationId：" + extend.getTollStationId() + "\n" +
                            "tollLaneId：" + extend.getTollLaneId() + "\n" +
                            "timeUnix：" + extend.getTimeUnix() + "\n" +
                            "vehicleModel：" + extend.getVehicleModel() + "\n" +
                            "passStatus：" + extend.getPassStatus() + "\n" +
                            "reserve1：" + extend.getReserve1() + "\n" +
                            "staffNo：" + extend.getStaffNo() + "\n" +
                            "mtcSequenceNo：" + extend.getMtcSequenceNo() + "\n" +
                            "vehicleNumber：" + extend.getVehicleNumber() + "\n" +
                            "reserve2：" + extend.getReserve2() + "\n";
            dataList.add(consume);
        }
        return dataList;
    }

    /**
     * 启动该活动
     *
     * @param context 发起启动的活动
     * @param bundle  数据bundle
     */
    public static void actionStart(Context context, Bundle bundle) {
        Intent intent = new Intent(context, CardConsumeActivity.class);
        intent.putExtra(CONSUME_LIST_KEY, bundle);
        context.startActivity(intent);
    }
}
